unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,Class_Dict, ExtCtrls, RzPanel, RzButton, ImgList,
  Grids, AdvObj, BaseGrid, AdvGrid,Dialog_View,Class_Cnfg;

type
  TForm1 = class(TDialogView)
    IdFTP1: TIdFTP;
    Btnx_1: TButton;
    Btnx_2: TButton;
    Btnx_3: TButton;
    Tool_1: TRzToolbar;
    Btnx_4: TRzToolButton;
    Btnx_5: TRzToolButton;
    Btnx_6: TRzToolButton;
    il1: TImageList;
    Grid_1: TAdvStringGrid;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
    procedure Btnx_4Click(Sender: TObject);
    procedure Btnx_5Click(Sender: TObject);
    procedure Btnx_6Click(Sender: TObject);
  private
    FListCnfg :TCollection;//*list of *tfilecnfg
  protected
    procedure SetInitialize;override;
    procedure SetCommParams;override;
    procedure SetGridParams;override;
    procedure SetComboItems;override;
    procedure TryFreeAndNil;override;
  public
    procedure AddxCnfg;
    procedure EditCnfg;
    procedure DeltCnfg;
  public
    procedure InitCnfg;
    procedure SaveCnfg;
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzDebug,Class_KzUtils,NativeXmlObjectStorage,Dialog_EditCnfg;

{$R *.dfm}

procedure TForm1.AddxCnfg;
var
  CnfgA:TFileCnfg;
begin
  if FListCnfg=nil then
  begin
    FListCnfg:=TCollection.Create(TFileCnfg);
  end;

  try
    CnfgA:=TFileCnfg(FListCnfg.Add);
    if ViewEditCnfg(CnfgA)<>Mrok then
    begin
      FListCnfg.Delete(FListCnfg.Count-1);
      Exit;
    end;

    SaveCnfg;
  finally
  end;
end;

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  ListA:TStringList;
  ListB:TStringList;
begin
  try
    IdFTP1.Host:='www.2ccc.com';
    IdFTP1.Port:=21;
    IdFTP1.Username:='uploads';
    IdFTP1.Password:='uploads';
    {IdFTP1.Host:='192.168.0.10';
    IdFTP1.Username:='xmf';
    IdFTP1.Password:='xmf';}

    if not Self.IdFTP1.Connected then
    begin
      Self.IdFTP1.Connect();
    end;

    ListA:=TStringList.Create;
    Self.IdFTP1.List(ListA,'-');
    ListB:=TFileDict.ListIt(ListA);
    TKzUtils.TryFreeAndNil(ListB);
  except
    On E:Exception do
    begin
      raise E.Create(E.Message);
    end;
  end;
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
begin
  if IdFTP1.Connected then
  begin
    IdFTP1.Disconnect;
  end;
  IdFTP1.Host:='192.168.0.10';
  IdFTP1.Username:='xmf';
  IdFTP1.Password:='xmf';
  if not IdFTP1.Connected then
  begin
    IdFTP1.Connect();
  end;

  try
    IdFTP1.Put('00001.doc','00001.doc');
  except
    on E:Exception do
    begin
      raise E.Create(E.Message);
    end;
  end;
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
begin
  if IdFTP1.Connected then
  begin
    IdFTP1.Disconnect;
  end;
  IdFTP1.Host:='192.168.0.10';
  IdFTP1.Username:='xmf';
  IdFTP1.Password:='xmf';
  if not IdFTP1.Connected then
  begin
    IdFTP1.Connect();
  end;

  try
    IdFTP1.Delete('00001.doc');
  except
    on E:Exception do
    begin
      raise E.Create(E.Message);
    end;
  end;  
end;

procedure TForm1.DeltCnfg;
begin

end;

procedure TForm1.EditCnfg;
begin

end;

procedure TForm1.SetComboItems;
begin
  inherited;

end;

procedure TForm1.SetCommParams;
begin
  inherited;

end;

procedure TForm1.SetGridParams;
begin
  inherited;

end;

procedure TForm1.SetInitialize;
begin
  FListCnfg:=TCollection.Create(TFileCnfg);
  inherited;

end;

procedure TForm1.TryFreeAndNil;
begin
  inherited;
  if FListCnfg<>nil then TKzUtils.TryFreeAndNil(FListCnfg);
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
begin
  AddxCnfg;
end;

procedure TForm1.Btnx_5Click(Sender: TObject);
begin
  DeltCnfg;
end;

procedure TForm1.Btnx_6Click(Sender: TObject);
begin
  EditCnfg;
end;

procedure TForm1.InitCnfg;
begin
  if not FileExists(TKzUtils.ExePath+'Config.xml') then Exit;


  //NativeXmlObjectStorage.ObjectLoadFromXmlFile();
end;

procedure TForm1.SaveCnfg;
begin
  NativeXmlObjectStorage.ObjectSaveToXmlFile(FListCnfg,TKzUtils.ExePath+'Config.xml');
end;

end.
